package cn.stylefeng.guns.modular.recy.controller;
/*
 */

import cn.stylefeng.roses.core.base.controller.*;
import org.springframework.stereotype.*;
import cn.stylefeng.guns.modular.recy.service.*;
import org.springframework.beans.factory.annotation.*;
import cn.stylefeng.roses.core.reqres.response.*;
import cn.stylefeng.guns.modular.recy.entity.*;
import java.io.*;
import cn.stylefeng.guns.core.common.page.*;
import com.baomidou.mybatisplus.core.metadata.*;
import com.baomidou.mybatisplus.core.conditions.*;
import cn.stylefeng.guns.modular.recy.vo.*;
import cn.stylefeng.guns.modular.recy.utils.*;
import cn.hutool.core.bean.*;
import java.util.stream.*;
import cn.stylefeng.guns.modular.recy.warpper.*;
import com.baomidou.mybatisplus.core.conditions.query.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.*;
import java.util.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.*;

@Controller
@RequestMapping({ "/article" })
public class ArticleController extends BaseController
{
    private String PREFIX;
    @Autowired
    private ArticleService articleService;
    
    public ArticleController() {
        this.PREFIX = "/modular/recy/article/";
    }
    
    @RequestMapping({ "" })
    public String index() {
        return this.PREFIX + "article.html";
    }
    
    @RequestMapping({ "/add" })
    public String articleAdd() {
        return this.PREFIX + "article_add.html";
    }
    
    @RequestMapping({ "/edit" })
    public String articleUpdate(@RequestParam("id") final String id) {
        return this.PREFIX + "article_edit.html";
    }
    
    @RequestMapping({ "/detail/{id}" })
    @ResponseBody
    public ResponseData detail(@PathVariable final String id) {
        final Article article = (Article)this.articleService.getById((Serializable)id);
        return (ResponseData)ResponseData.success(article);
    }
    
    @RequestMapping({ "/list" })
    @ResponseBody
    public Object list(final Article articleQuery) {
        final QueryWrapper<Article> articleQueryWrapper = ControllerUtil.createQuery(articleQuery, this.getHttpServletRequest());
        final Page<Article> page = (Page<Article>)LayuiPageFactory.defaultPage();
        final IPage<Article> page2 = (IPage<Article>)this.articleService.page((IPage)page, (Wrapper)articleQueryWrapper);
        final List<ArticleVO> articleVOList = EntityBind.bind(page2.getRecords(), ArticleVO.class);
        final List<Map<String, Object>> list = articleVOList.stream().map(article -> BeanUtil.beanToMap(article)).collect(Collectors.toList());
        page2.setRecords((List)new ArticleWrapper(list).wrap());
        return LayuiPageFactory.createPageInfo(page2);
    }
    
    @RequestMapping({ "/addItem" })
    @ResponseBody
    public Object add(final Article article) {
        this.articleService.save(article);
        return ArticleController.SUCCESS_TIP;
    }
    
    @RequestMapping({ "/delete" })
    @ResponseBody
    public Object delete(@RequestParam final String id) {
        this.articleService.removeById((Serializable)id);
        return ArticleController.SUCCESS_TIP;
    }
    
    @RequestMapping({ "/editItem" })
    @ResponseBody
    public Object update(final Article article) {
        this.articleService.updateById(article);
        return ArticleController.SUCCESS_TIP;
    }
    
    @RequestMapping(value = { "/delItems" }, method = { RequestMethod.POST })
    @ResponseBody
    public Object delItem(@RequestBody final String[] ids) {
        this.articleService.removeByIds((Collection)Arrays.asList(ids));
        return ArticleController.SUCCESS_TIP;
    }
    
    @RequestMapping({ "/show" })
    public Object show(final String id, final Model model) {
        final Article article = (Article)this.articleService.getById((Serializable)id);
        final Map map = BeanUtil.beanToMap(article);
        model.addAttribute("article", new ArticleWrapper(map).wrap());
        return this.PREFIX + "article_show.html";
    }
}
